import net.chrisrichardson.ec2deployer.cluster.ClusterManager

pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File("${pluginHome}/scripts/ExplodedWar.groovy")
includeTargets << new File("${pluginHome}/scripts/CloudToolsInit.groovy")

target('default': "Redeploy to EC2") {
    redeploy()
}

target(redeploy: "The implementation task") {
  depends(explodedWar, initCloudToolsService)
    // TODO - Fix for grails bug
    Ant.replace(file: "explodedWar/${grailsAppName}/WEB-INF/web.xml", token: "log4jConfigLocation", value: "log4jConfigLocationCloudToolsPluginUtil")
    cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
        cluster.redeploy()
    }
    event("StatusFinal", ["Finished redeploying cluster"])

}